package cn.test.learnkotlin.v1

class FExtends {

    private class Example : Any()

    /**
     * 构造函数
     */
    private open class Person6(var name: String, var age: Int) {}

    /**
     * 子类有主构造函数
     */
    private class Student(name: String, age: Int, var no: String, var score: Int) : Person6(name, age) {
    }

    /**
     * 子类没有主构造函数
     */
    private class Student2 : Person6 {
        constructor(name: String, age: Int) : super(name, age) {}
    }

    private open class Person7(name: String) {
        constructor(name: String, age: Int) : this(name) {
            println("----基类次构造函数----")
        }
    }

    private class Student3 : Person7 {
        constructor(name: String, age: Int, no: String, score: Int) : super(name, age) {
            println("----继承类次级构造函数----")
        }
    }

    /**
     * 重写
     */
    private open class Person8 {
        open fun study() {
            println("我在学习")
        }
    }

    private class Student4 : Person8() {
        override fun study() {    // 重写方法
            println("我在读大学")
        }
    }

    private open class A {
        open fun f() {
            print("A")
        }

        fun a() {
            print("a")
        }
    }

    interface B {
        fun f() {
            print("B")
        }

        fun b() {
            print("b")
        }
    }

    private class C : A(), B {
        override fun f() {
            super<A>.f()
            super<B>.f()
        }
    }

    private fun fooOverride() {
        Student4().study()
        C().f()
    }

    /**
     * 属性重写
     */
    private open class Foo4 {
        open val x: Int = 5
    }

    private class Bar : Foo4() {
        override var x = 6
    }

    private class Bar2(override var x: Int) : Foo4() {}

    fun main() {
        fooOverride()
    }
}

fun main() {
    FExtends().main()
}